package com.new_wear.project.system.log.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.log.domain.CstUserIntegralLog;
import com.new_wear.project.system.log.service.ICstUserIntegralLogService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 用户 - 等级积分日志Controller
 * 
 * @author new_wear
 * @date 2019-12-31
 */
@Controller
@RequestMapping("/system/log")
public class CstUserIntegralLogController extends BaseController
{
    private String prefix = "system/log";

    @Autowired
    private ICstUserIntegralLogService cstUserIntegralLogService;

    @RequiresPermissions("system:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询用户 - 等级积分日志列表
     */
    @RequiresPermissions("system:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CstUserIntegralLog cstUserIntegralLog)
    {
        startPage();
        List<CstUserIntegralLog> list = cstUserIntegralLogService.selectCstUserIntegralLogList(cstUserIntegralLog);
        return getDataTable(list);
    }

    /**
     * 导出用户 - 等级积分日志列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "用户 - 等级积分日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CstUserIntegralLog cstUserIntegralLog)
    {
        List<CstUserIntegralLog> list = cstUserIntegralLogService.selectCstUserIntegralLogList(cstUserIntegralLog);
        ExcelUtil<CstUserIntegralLog> util = new ExcelUtil<CstUserIntegralLog>(CstUserIntegralLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 新增用户 - 等级积分日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户 - 等级积分日志
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "用户 - 等级积分日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CstUserIntegralLog cstUserIntegralLog)
    {
        return toAjax(cstUserIntegralLogService.insertCstUserIntegralLog(cstUserIntegralLog));
    }

    /**
     * 修改用户 - 等级积分日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CstUserIntegralLog cstUserIntegralLog = cstUserIntegralLogService.selectCstUserIntegralLogById(id);
        mmap.put("cstUserIntegralLog", cstUserIntegralLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户 - 等级积分日志
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "用户 - 等级积分日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CstUserIntegralLog cstUserIntegralLog)
    {
        return toAjax(cstUserIntegralLogService.updateCstUserIntegralLog(cstUserIntegralLog));
    }

    /**
     * 删除用户 - 等级积分日志
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "用户 - 等级积分日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cstUserIntegralLogService.deleteCstUserIntegralLogByIds(ids));
    }
}
